﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Routing;
using Microsoft.Practices.Unity;
using Vit.Common;
using Vit.Web;
using Vit.Web.Models;
using Vit.Web.Providers;

namespace Vit.Mvc.Controllers
{
    public class PageController : UnityControllerBase
    {
        public ActionResult Visit()
        {
            if (CurrentPage != null)
            {
                if (!string.IsNullOrEmpty(CurrentPage.Area))
                    this.RouteData.DataTokens.Add("area", CurrentPage.Area);

                var theme = WebUnity.Current.PortalService.Run(p => p.GetCurrentTheme(), o => o != null);

                string viewNmae = string.Format("{0}/Pages/{1}", theme.Name, CurrentPage.ViewName);
                string masterNmae = string.Format("{0}/Masters/{1}", theme.Name, CurrentPage.MasterName);

                return View(viewNmae, masterNmae, CurrentPage);
            }
            else
            {
                return Redirect(Request.RawUrl);
            }
        }
    }
}
